package com.wythe.mall.adapter;

import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wythe.mall.R;
import com.wythe.mall.model.SizeBean;

import java.util.List;

/**
 * 适配器
 *
 * @author MapleStory
 * @ qq 1002285057
 * @ project https://gitee.com/MapStory/Shopwt-Android
 */

public class SpecListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final List<SizeBean> arrayList;
    private onItemClickListener onItemClickListener;

    public SpecListAdapter(List<SizeBean> arrayList) {
        this.arrayList = arrayList;
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final SizeBean hashMap = arrayList.get(position);
        ItemViewHolder itemHolder = (ItemViewHolder) holder;
        itemHolder.mainTextView.setText(hashMap.getTitle());

//        if (true) {
            itemHolder.mainTextView.setTextColor(Color.WHITE);
            itemHolder.mainTextView.setBackgroundResource(R.drawable.selector_border_primary);
//        } else {
//            itemHolder.mainTextView.setTextColor(Color.GRAY);
//            itemHolder.mainTextView.setBackgroundResource(R.drawable.selector_border_selector);
//        }

        itemHolder.mainLinearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onClick(position, hashMap);
                }
            }
        });

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup group, int viewType) {
        View view = LayoutInflater.from(group.getContext()).inflate(R.layout.item_list_spec, group, false);
        return new ItemViewHolder(view);
    }

    public void setOnItemClickListener(onItemClickListener listener) {

        this.onItemClickListener = listener;

    }

    public interface onItemClickListener {

        void onClick(int position, SizeBean bean);

    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {

        private LinearLayoutCompat mainLinearLayout;
        private AppCompatTextView mainTextView;

        private ItemViewHolder(View view) {
            super(view);
            mainLinearLayout = (LinearLayoutCompat) view.findViewById(R.id.mainLinearLayout);
            mainTextView = (AppCompatTextView) view.findViewById(R.id.mainTextView);
        }

    }

}
